define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wwh/development/index' + location.search,
                    add_url: 'wwh/development/add',
                    edit_url: 'wwh/development/edit',
                    del_url: 'wwh/development/del',
                    multi_url: 'wwh/development/multi',
                    table: 'wwh_development',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
				fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'year', title: __('Year')},
                        {field: 'lang', title: __('Lang'), searchList: {"1":__('Lang 1'),"2":__('Lang 2')}, custom: {1: 'success', 2: 'warning'}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            // 弹窗窗口大小
            table.on('post-body.bs.table',function(e, settings, json, xhr){
                $(".btn-add").data("area", ['80%','80%']);
                $(".btn-editone").data("area", ['80%','80%']);
            });

            // TAB选项卡默认选中简体中文
            $('ul.nav-tabs li a[data-toggle="tab"]').eq(0).trigger("click");

            // 获取TAB选项卡值,通过options.extend.add_url传递
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var options = table.bootstrapTable('getOptions');
                options.extend.add_url = 'wwh/development/add?lang=' + $(this).data('value');
            });

        },
        add: function () {
            // 将TAB选项卡赋值给lang
            $('#c-lang option').each(function(){
                if($(this).attr('value') == Fast.api.query('lang'))
                {
                    $(this).attr('selected', 'selected');
                }
            });
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});